package com.wenli.lt.controller;
import com.wenli.lt.util.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author xy
 * 2020/11/26
 */
@Slf4j
@RestControllerAdvice(annotations = RestController.class)
public class AdviceController {
    private static final String UNIFIED_FAIL_MSG = "服务器内部错误";

    /**
     * 控制器层公共异常处理
     *
     * @param e 接收异常
     * @return 返回结果
     */
    @ExceptionHandler(Exception.class)
    public CommonResponse bnException(Exception e) {
        e.printStackTrace();
        log.error("error cause", e.getCause());
        return new CommonResponse<>(CommonResponse.ERROR_CODE, UNIFIED_FAIL_MSG);
    }

}
